Skip to content

fix: open job links on a phone, show a comment's replies in HN's order, and three smaller fixes - #340

Merged
therealsama merged 6 commits into
mainfrom
fix/phone-job-links-reply-order-url-parens
Nov 22, 2026
Merged

therealsama merged 6 commits into
mainfrom
fix/phone-job-links-reply-order-url-parens

Conversation

@therealsama

@therealsama therealsama commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes five bugs: four found while testing against live HN data, and one reported from the app installed on a phone. Each fix is its own commit.

Bug fixes

  • On a phone, a direct link to a job showed "This item is not a story". The link resolver sent every top-level item to the swipe story viewer, which only takes stories, so a link such as #/item/50593679 led nowhere. It now tells stories from jobs and opens a job on the item page, as desktop does. The e2e test that expected the old message, added in the type refactor 4b36771 with no product reason, now checks for the item page.
  • A comment's own page listed its replies oldest first. Algolia's item tree and search return replies in creation order. HN ranks them, and the story thread already takes that order from Firebase's kids. The page now sorts the replies it first shows by the comment's own Firebase kids, read once Algolia's item has loaded. Nested and flagged replies take HN's order once the story's comments load. With only that second step, the replies on comment 50593925 jumped into place 0.6 to 5.4s after they appeared. With the first read, the order settles about 150ms after first paint. The replacement now also applies when it adds no replies, and a thread too big for search is ordered too.
  • Auto-linked URLs stopped at "(". https://en.wikipedia.org/wiki/Foil_(narrative) was linked only up to Foil_. The auto-linker now keeps balanced parentheses. It still leaves out a closing one that wraps the whole URL, as in (see https://…). Worst-case input runs in about 0.2ms, so there's no backtracking risk.
  • A flagged comment with no replies lost its story link. A comment that Algolia 404s is read from Firebase, which has no story id, so the page took the story from its first reply. With no replies, as on #/item/234621, the story link and title were missing. It now walks up the comment's Firebase parent chain to the story, up to 100 levels.
  • The app installed on a phone could open on an old story, and the logo then showed another. A phone opens a feed from the stories cached on the last visit, which can be up to a day old, and then refreshes them. The refresh keeps every story the reader has reached, including the first one on screen, so the app stayed on a story that might no longer lead the feed. The logo opened the feed again from the refreshed cache and showed the current first story. A feed now opens from its cache only if the cache is under five minutes old. An older cache waits for the refresh behind the loading skeleton, and is shown if the refresh fails, the app is offline, or three seconds pass, as on a stalled connection, where Firebase waits with no timeout. A story URL still opens on that story. The e2e test for a refresh that lands after a swipe now seeds a minute-old cache, so the feed still opens from it.

Known limitations

  • The parent walk for a flagged comment with no replies reads one level at a time, and the comment's page waits for it.
  • A URL with an unbalanced parenthesis inside it, such as https://a.com/a)b or https://a.com/x(y, now ends the link at that parenthesis, where the old auto-linker linked all of it. This should be rare: HN links nearly every URL itself, and the auto-linker skips those. Of about 2,600 recent comments and posts, one had a URL HN left unlinked, with no parentheses.
  • Ordering adds Firebase reads to a comment's page: one for the comment when it has more than one reply, then one for each comment in its thread with more than one reply once the story's comments load.
  • On a phone, opening or switching to a feed whose cache is over five minutes old shows the loading skeleton until the refresh lands, about 1s on a live connection and up to three seconds on a stalled one, where it used to show the cached stories at once.
  • A cache under five minutes old still opens on its first story, and keeps it on screen if the refresh moves it down.

Testing

Each new test fails with its fix reverted.

  • npm run typecheck: passed
  • npm run lint: passed
  • npm run test:run: passed, 1191 tests. Each commit also passes typecheck, lint and the unit tests on its own.
  • npm run build: passed
  • npx playwright test --project=chromium --project="Mobile Chrome": 465 passed, 9 skipped
  • Not run locally: the Firefox and Mobile Safari e2e projects, whose browsers aren't installed.
  • Checked by hand on the dev server against live HN:
    • On a phone, job 50593679 opens on the item page.
    • Flagged comment 234621 links to "Y Combinator".
    • The replies on comment 50593925 match HN's order.
    • On a phone, a launch with a three-hour-old cache led by the story now fourth on HN showed the skeleton, then HN's current first story at about 1.2s, and the logo showed the same story.
  • Checked with Playwright on the production build, with the service worker in control, on a phone launch with a three-hour-old cache: the skeleton gave way to the refreshed stories at about 1.3s on a live connection, and to the cached ones at about 3.1s on a stalled connection and with only Firebase blocked. Offline, the cached stories showed at once.

On a phone, a direct link to a job, such as #/item/50593679, showed
"This item is not a story". The link resolver sent every top-level item
to the story viewer, which only takes stories. It now tells stories from
jobs and opens a job on the item page, as desktop does.

The e2e test that expected the old message now checks for the item page.
A comment's page listed its replies oldest first, the order Algolia's
item tree and search return them in, while HN ranks them. The story
thread already takes the order from Firebase's kids.

The page now sorts the replies it first shows by the comment's own
Firebase kids, read once Algolia's item has loaded, so the order settles
about 150ms after the replies appear instead of seconds later. Nested
replies and flagged ones take HN's order once the story's comments load.
That replacement now also happens when it adds no replies, and a thread
too big for search is ordered too instead of keeping the item tree.
A plain-text URL in a comment, such as
https://en.wikipedia.org/wiki/Foil_(narrative), was linked only up to
the "(". The auto-linker now keeps balanced parentheses in a URL and
still leaves out a closing one that wraps the whole URL, as in
"(see https://...)". An unbalanced "(" inside a URL still ends the link.
A flagged or deleted comment that Algolia 404s is read from Firebase,
which has no story id. It took the story from its first reply, so with
no replies, as for #/item/234621, its page lost the story link and
title. It now walks up the comment's Firebase parent chain to the story,
up to 100 levels, and goes without the link only if a read fails.
@therealsama
therealsama force-pushed the fix/phone-job-links-reply-order-url-parens branch from ab85418 to 5143b3b Compare November 22, 2026 00:22
…d one

On a phone, a feed opens from the stories cached on the last visit and
then refreshes them. The refresh keeps every story the reader has
reached, including the first one on screen, so an app launched from a
cache hours old stayed on a story that may no longer lead the feed. The
logo then opened the feed again from the refreshed cache and showed a
different first story.

Opening a feed now uses its cache only if it is under five minutes old.
An older cache waits for the refresh behind the loading skeleton, and is
shown if the refresh fails or the app is offline, where the refresh never
settles. A story URL shows that story either way, as before.

The e2e test for a refresh that lands after a swipe now seeds a
minute-old cache, so the feed still opens from it.
@therealsama therealsama changed the title fix: open job links on a phone, show a comment's replies in HN's order, and two smaller fixes fix: open job links on a phone, show a comment's replies in HN's order, and three smaller fixes Nov 22, 2026
…ection

A feed opened from a cache over five minutes old waits for the refresh
behind the loading skeleton. Firebase waits for a connection with no
timeout, and the connection check counts its own timeout as unknown, so on
a stalled connection, or with only Firebase blocked, the skeleton stayed
for good. The cached stories now show after three seconds, as they did at
once before the wait.
@therealsama
therealsama merged commit faaffe3 into main Nov 22, 2026
4 checks passed
@therealsama
therealsama deleted the fix/phone-job-links-reply-order-url-parens branch November 22, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants